// pages/order/confirm/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    latitude: "",
    longitude: "",
    scrollTop:0,
    // 标记点 当前位置
    markers: [],    
    // 圆
    circles: [],
    // 控件 回到当前位置
    controls: [],
    //停车场详情dialog
    isParkDialogShow:false,
     //停车场详情dialog中的加载
     isParkDialogLoading:false,
    //当前选择的停车场
    selectedPark:{},
    //车辆信息列表
    parkCarsInfo:[]
  },
  onOrder(){
    //createOrder
    wx.showLoading({
      title: '订单生成中',
    })
    setTimeout(()=>{
      wx.hideLoading({
        success: (res) => {
          wx.requestPayment(
            {
            "timeStamp": Date.parse(new Date()),
            "nonceStr": "",
            "package": "",
            "signType": "MD5",
            "paySign": "",
            "success":function(res){},
            "fail":function(res){},
            "complete":function(res){}
            })
        },
      })
    },1000)
  },
  setSamePark(){
    console.log(1)
    this.setData({selectedPark:this.data.markers[0]})

  },
  showParkDialog(){
    this.setData({isParkDialogShow:true})
    console.log(this.data.isParkDialogShow)

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var thisBlock = this;
    wx.getLocation({
      type: "wgs84",
      success: function(res) {
        thisBlock.loadParks(res)

        console.log(res);
        thisBlock.data.markers.push( {iconPath: "/images/map/position.png",
        id:0,
        mType:'self',
        latitude: res.latitude,
        longitude: res.longitude,
        width:35,
        height:35,
        title:"",
      label: {content:"我的位置"},
      anchor:{}})
      thisBlock.reloadMap(res)
      },
    })
  },
  dismissDialog(){
    this.setData({isParkDialogShow:false})

  },
  
  onMarkerTap(e) {

    this.setData({isParkDialogShow:false})
    let markerId = e.markerId
    let target = this.data.markers.find(it=> it.id === markerId)
    if(!target) return
    this.setData({selectedPark:target})
    console.log("markertap",  this.data.selectedPark)
    
    // let markerId = e.markerId
    // let target = this.data.markers.find(it=> it.id === markerId)
    // console.log("markertap", e.markerId,target)
    // if(!target) return
    // this.data.selectedPark = target
    // if(target.mType === "park"){
    //   this.getCarsByPrakId(target.id)
    //   wx.showLoading({
    //     title: '加载车辆信息中',
    //   })
     
     
    // }
    },
//刷新地图markers
reloadMap:function(res){
  var thisBlock = this;
      thisBlock.setData({
        latitude: res.latitude,
        longitude: res.longitude,  
        //自身位置图标
        markers: thisBlock.data.markers ,

        circles: [{latitude: res.latitude,
          longitude: res.longitude,
          radius: 10,
          strokeWidth: 2,
          fillColor: "#FAFAD2",
          color: "#90EE90"}],

        controls: [{id:1001,
          position:{left:10, top:10, width:35, height:35},
          iconPath:"/images/map/returntomap.png",
          clickable:true}],
       
      })
      console.log('marker',this.data.markers)

},
//加载停车场列表
loadParks:function(res){
  let data =  [{
   mType:'park',
   name:'停车场1',
   iconPath: "/images/map/park.png",
   id: Date.parse(new Date()),
   latitude: res.latitude+0.001,
   longitude: res.longitude+0.001,
   width: 50,
   height: 50,
   title: "",
   label: {content:"标题"},
   anchor: {}
 },{
   iconPath: "/images/map/park.png",
   mType:'park',
   name:'停车场2',

   id: Date.parse(new Date())+1,
   latitude: 31.99100,
   longitude: 118.7700,
   width: 50,
   height: 50,
   title: "",
   label: {content:"标题"},
   anchor: {}
 }]
 console.log('loading park')
 this.data.markers = this.data.markers.concat(data)
   
 },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})